import { fetchInventoryList } from '@/service/inventory';
import ProTable, {
    ProColumnType,
    ProTableProps,
    RequestData,
} from '@ant-design/pro-table';
import { DataState } from './interface';

const columns: ProColumnType<DataState>[] = [
    // {
    //     title: 'RFID编号',
    //     key: 'rfid',
    //     dataIndex: 'rfid',
    //     valueType: 'text',
    // },
    // {
    //     title: '编号',
    //     key: 'id',
    //     dataIndex: 'id',
    // },
    {
        title: 'ISBN编号',
        key: 'isbn',
        dataIndex: 'isbn',
    },
    {
        title: '书名',
        key: 'book_name',
        dataIndex: 'book_name',
    },
    {
        title: '作者',
        key: 'author',
        dataIndex: 'author',
    },
    {
        title: '类别',
        key: 'cate_id',
        dataIndex: 'cate_name',
    },
    {
        title: '数量',
        key: 'count',
        dataIndex: 'count',
    },
];

export default function Inventory() {
    const dataSourceRequest: ProTableProps<DataState, {}>['request'] = async ({
        pageSize = 10,
        current = 1,
    }): Promise<RequestData<DataState>> => {
        const response = await fetchInventoryList({ pageSize, current });

        if (response.code !== 200) {
            return {
                total: 0,
                data: [],
            };
        }

        return {
            total: Number(response.data?.total || 0),
            data: response.data?.data || [],
        };
    };

    return (
        <div style={{ padding: '16px 0px 0px', background: '#fff' }}>
            <ProTable<DataState>
                columnEmptyText={false}
                options={false}
                search={false}
                columns={columns}
                request={dataSourceRequest}
                scroll={{ x: 1000, y: 500, scrollToFirstRowOnChange: true }}
            />
        </div>
    );
}
